//
//  wishImageViewController.m
//  ForeverLove
//
//  Created by lanou3g on 15/11/18.
//  Copyright © 2015年 文萱竹. All rights reserved.
//

#import "wishImageViewController.h"

@interface wishImageViewController ()

- (IBAction)backDidClicked:(UIBarButtonItem *)sender;
- (IBAction)achieveDidClicked:(UIBarButtonItem *)sender;

@property (weak, nonatomic) IBOutlet UITextView *myTextView;
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;


@end

@implementation wishImageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.myImageView.image = [UIImage imageWithData:self.myImage];
    
//    self.myBlock(self.myTextView.text);
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)backDidClicked:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)achieveDidClicked:(UIBarButtonItem *)sender {
    if (self.myTextView.text.length == 0) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.myTextView.frame)/2 - 55, CGRectGetMaxY(self.myTextView.frame)/2 -15, 110, 30)];
        label.text = @"写点什么吧";

        [self.view addSubview:label];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [UIView animateWithDuration:0.6f animations:^{
                label.alpha = 0;
            } completion:^(BOOL finished) {
                label.hidden = YES;
            }];
        });
    }else{
        NSString *textStr = self.myTextView.text;
        NSData *imageData = UIImageJPEGRepresentation(self.myImageView.image, 0.5);
        
        NSArray *nameArray = @[textStr, imageData];
        
        NSDictionary *dic = [NSDictionary dictionaryWithObject:nameArray forKey:@"imageAndText"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"image" object:nil userInfo:dic];
        [self.navigationController popViewControllerAnimated:YES];
    }
}
@end
